<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Symbol</title>
</head>
<body>
  
</body>

<script type="text/javascript">

  // Symbol：原始数据类型，它表示独一无二的
  // 最大的用途：用来定义对象的私有变量
  const name1 = Symbol('chengjunyu')
  const name2 = Symbol('chengjunyu')
  console.log(name1 === name2)


  let s1 = Symbol('name')
  console.log(s1);
  let person = {
    [s1]: 'chengjunyu1'
  }
  // person[s1] = 'chengjunyu'
  console.log(person)
  // 如果用Symbol定义的对象中的变量，取值时一定要用[变量名]
  console.log(person[s1])

  for(let key in person) {
    console.log(key);
  }
  console.log(Object.keys(person));


  // 获取Symbol声明的属性
  let o = Object.getOwnPropertySymbols(person)
  console.log(o)
  console.log(o[0])
  
  let r = Reflect.ownKeys(person)
  console.log(r);
  console.log(r[0]);
</script>
</html>